#include "userinfowindow.h"
#include <QGridLayout>
#include <QCursor>
UserInfoWindow::UserInfoWindow(QWidget* parent, const UserInfo& user)
    : QDialog(parent), userInfo(user)
{
    setFixedSize(370, 200);
    setWindowIcon(QIcon(":/resource/images/logo.png"));
    setWindowTitle("好友信息");
    setAttribute(Qt::WA_DeleteOnClose); //自动销毁
    move(QCursor::pos() - QPoint(100, 100));

    QGridLayout* layout = new QGridLayout();
    layout->setAlignment(Qt::AlignTop);
    layout->setHorizontalSpacing(20);
    layout->setVerticalSpacing(5);
    layout->setContentsMargins(60, 20, 20, 0);
    setLayout(layout);

    int height = 30;
    int width = 70;
    QString tagSS = "QLabel { font-size: 14px; font-weight: 800; }";
    QString btnSS = "QPushButton { border: 1px solid rgb(210, 210, 210); background-color: transparent; border-radius: 5px; }";
    btnSS += "QPushButton:pressed { background-color: rgb(201, 201, 201);}";


    avatar = new QPushButton();
    avatar->setFixedSize(70, 70);
    avatar->setIconSize(QSize(70, 70));
    avatar->setIcon(user.icon);

    //id
    idTag = new QLabel();
    idTag->setText("序号");
    idTag->setFixedSize(width, height);
    idTag->setStyleSheet(tagSS);

    idLabel = new QLabel();
    idLabel->setText(user.userId);
    idLabel->setFixedSize(width, height);
    //name
    nameTag = new QLabel();
    nameTag->setText("昵称");
    nameTag->setFixedSize(width, height);
    nameTag->setStyleSheet(tagSS);

    nameLabel = new QLabel();
    nameLabel->setText(user.nickName);
    nameLabel->setFixedSize(width, height);


    //phone
    phoneTag = new QLabel();
    phoneTag->setText("电话");
    phoneTag->setFixedSize(width, height);
    phoneTag->setStyleSheet(tagSS);

    phoneLabel = new QLabel();
    phoneLabel->setText(user.phone);
    phoneLabel->setFixedSize(width, height);


    //PushButton
    applyBtn = new QPushButton();
    applyBtn->setFixedSize(width, height);
    applyBtn->setText("申请好友");
    applyBtn->setStyleSheet(btnSS);


    sendMessageBtn = new QPushButton();
    sendMessageBtn->setFixedSize(width, height);
    sendMessageBtn->setText("发送消息");
    sendMessageBtn->setStyleSheet(btnSS);

    deleteFriendBtn = new QPushButton();
    deleteFriendBtn->setFixedSize(width, height);
    deleteFriendBtn->setText("删除好友");
    deleteFriendBtn->setStyleSheet(btnSS);



    //添加到布局管理器中
    layout->addWidget(avatar, 0, 0, 3, 1);

    layout->addWidget(idTag, 0, 1);
    layout->addWidget(idLabel, 0, 2);

    layout->addWidget(nameTag, 1, 1);
    layout->addWidget(nameLabel, 1,2);

    layout->addWidget(phoneTag, 2, 1);
    layout->addWidget(phoneLabel, 2, 2);

    layout->addWidget(applyBtn, 3, 0);
    layout->addWidget(sendMessageBtn, 3, 1);
    layout->addWidget(deleteFriendBtn, 3, 2);

}
